package com.hehao.controller;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * @Author Damon
 * @Date 2024/5/11 13:56
 */
@RestController
@RequestMapping("/webflux")
public class DemoController {

    @GetMapping(value = "/hello", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> hello() {
        return Flux.create(sink -> {
            Scanner scanner = new Scanner(System.in);
            while (true) {
                String input = scanner.nextLine();
                if ("exit".equals(input)) {
                    sink.complete();
                    break;
                } else {
                    sink.next(input);
                }
            }
        });
    }

}
